
def cov_func(x_arr, y_arr):
    x_num = len(x_arr)
    x_mean = np.mean(x_arr)
    y_mean = np.mean(y_arr)
    return np.mean((x_arr-x_mean)*(y_arr-y_mean))*(x_num)/(x_num-1)

if __name__ == '__main__':
    import numpy as np
    x_arr = np.arange(1,10,.05)
    y_arr = 3* x_arr
    x = np.stack((x_arr,y_arr),axis = 0)
    print("cov array\n",np.cov(x_arr,y_arr))
    print(cov_func(x_arr,y_arr),cov_func(x_arr,x_arr))
